// scripts/test-bcrypt-compare.js
import { Client } from 'pg';
import bcrypt from 'bcrypt';

const client = new Client({
    host: '43.162.111.101',
    port: 5432,
    user: 'myuser',
    password: '123456',
    database: 'dating_app',
});

async function run() {
    await client.connect();
    const res = await client.query("SELECT id, phone, password FROM users WHERE phone = '13104332181' LIMIT 1");
    if (res.rows.length === 0) {
        console.log('找不到该用户');
        await client.end();
        return;
    }
    const user = res.rows[0];
    console.log('数据库中 password:', user.password);

    const plain = '123456'; // 你要测试的明文密码（和前端发送的一样）
    const ok = await bcrypt.compare(plain, user.password);
    console.log('bcrypt.compare 结果：', ok); // true 表示验证通过
    await client.end();
}

run().catch(err => {
    console.error(err);
    process.exit(1);
});
